package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.IOrderHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@DefaultProperties(defaultFallback = "globalHandler")
public class OrderHystrixController {
    @Resource
    private IOrderHystrixService orderHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable Integer id) {
        return orderHystrixService.paymentInfo_OK(id);
    }

//    @HystrixCommand(commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
//    }, fallbackMethod = "timeOutHandler")
    @HystrixCommand
    @GetMapping("/consumer/payment/hystrix/time-out/{id}")
    public String paymentInfo_TimeOut(@PathVariable Integer id) {
        int a = 10 / 0;
        return orderHystrixService.paymentInfo_TimeOut(id);
    }


    public String timeOutHandler(@PathVariable Integer id) {
        return "消费端 80 线程池： " + Thread.currentThread().getName() + "系统繁忙，请稍后再试！" + id + "\t ┭┮﹏┭┮呜呜";
    }


    public String globalHandler() {
        return "消费端 80 全局处理 线程池： " + Thread.currentThread().getName() + "系统繁忙，请稍后再试！\t ┭┮﹏┭┮呜呜";
    }


}
